package com.turing.post.organization.impl;

import java.math.BigInteger;
import java.util.Date;

import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;

import com.turing.post.common.util.Global;
import com.turing.post.common.util.IdType;
import com.turing.post.common.util.IdTypeDao;
import com.turing.post.common.util.PCPSCommonDao;
import com.turing.post.common.util.SysOpUser;
import com.turing.post.common.util.SysOpUserDao;
import com.turing.post.common.util.SysOperLog;
import com.turing.post.common.util.SysOperLogDao;
import com.turing.post.organization.util.IssueBranch;
import com.turing.post.organization.util.IssueBranchBusiness;
import com.turing.post.organization.util.IssueCompany;
import com.turing.post.organization.util.IssueCompanyBusiness;
import com.turing.post.organization.util.IssueCompanyDao;
import com.turing.post.organization.util.OrganApplicationException;
import com.turing.post.organization.util.OrganRespCode;
import com.turing.post.organization.util.SaleBranchDao;
import com.turing.post.organization.util.SysBranch;
import com.turing.post.organization.util.SysBranchDao;
import com.turing.post.organization.util.SysBranchSubord;
import com.turing.post.organization.util.SysBranchSubordDao;
import com.turing.post.salesmanage.util.PersonalCustom;
import com.turing.post.salesmanage.util.PersonalCustomDao;
import com.turing.post.salesmanage.util.SalesManageApplicationException;
import com.turing.post.salesmanage.util.SalesManageRespCode;
import com.turing.post.util.PCPSApplicationException;
import com.turing.post.util.PCPSUtil;
import com.turing.post.util.PCPSWebInput;
import com.turing.post.util.SHA1;

/**
 * @author zxp
 * @Dec 17, 2012
 */
@Stateless(mappedName = "organization.impl.IssueCompanyBusinessImpl")
@Remote
@Local
public class IssueCompanyBusinessImpl implements IssueCompanyBusiness {

	@EJB(mappedName = "organization.impl.IssueCompanyDaoImpl")
	private IssueCompanyDao issueCompanyDaoImpl;

	@EJB(mappedName = "organization.impl.IssueBranchBusinessImpl")
	private IssueBranchBusiness issueBranchBusinessImpl;

	@EJB(mappedName = "organization.impl.SysBranchDaoImpl")
	private SysBranchDao sysBranchDaoImpl;

	@EJB(mappedName = "organization.impl.SaleBranchDaoImpl")
	private SaleBranchDao saleBranchDaoImpl;

	@EJB(mappedName = "organization.impl.SysBranchSubordDaoImpl")
	private SysBranchSubordDao sysBranchSubordDaoImpl;

	// 用户表
	@EJB(mappedName = "common.impl.SysOpUserDaoImpl")
	private SysOpUserDao sysOpUserDaoImpl;

	@EJB(mappedName = "	common.impl.PCPSCommonDaoImpl")
	private PCPSCommonDao commonDaoImpl;

	@EJB(mappedName = "common.impl.SysOperLogDaoImpl")
	private SysOperLogDao sysOperLogDaoImpl;

	@EJB(mappedName = "common.impl.IdTypeDaoImpl")
	private IdTypeDao idTypeDaoImpl;

	@EJB(mappedName = "salesmanage.impl.PersonalCustomDaoImpl")
	private PersonalCustomDao personalCustomDaoImpl;

	@EJB(mappedName = "common.impl.PCPSCommonDaoImpl")
	private PCPSCommonDao pcpsCommonDaoImpl;

	@Override
	public void insertIssueCompanyInfo(PCPSWebInput webInput,
			IssueCompany issueCompany) throws PCPSApplicationException {
		// 平台管理人员才可添加发卡商，平台管理人员归属机构为NULL
		if (!PCPSUtil.isEmpty(webInput.getOperBranchNo())) {
			throw new OrganApplicationException(
					OrganApplicationException.ERRCODE_CATEGORY_APPLICATION,
					OrganRespCode.ISSUE_INSERT_UPDATE, "只有平台管理员才可创建发卡商!");
		}
		// 业务检查
		if (issueCompany == null) {
			throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL,
					"IssueCompany");
		}
		// 发卡商No
		if (PCPSUtil.isEmpty(issueCompany.getIssueCompanyNo())) {
			throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL,
					"IssueCompanyNo");
		}
		// 验证发卡商编号是否已经使用
		if (sysBranchDaoImpl.getSysBranchByBranchNo(issueCompany
				.getIssueCompanyNo()) != null) {
			throw new OrganApplicationException(
					OrganApplicationException.ERRCODE_CATEGORY_APPLICATION,
					"发卡商编号已经存在!");
		}
		// 发卡商名称
		if (PCPSUtil.isEmpty(issueCompany.getIssueCompanyName())) {
			throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL, "",
					"发卡商名称为空!");
		}
		// 平台租赁必须设置有效期
		if (issueCompany.getCategory().equals(
				IssueCompany.ISSUECOMPANY_CATEGORY_LEASE)) {
			if (issueCompany.getLeaseExpired() == null) {
				throw new OrganApplicationException(
						OrganApplicationException.ERRCODE_CATEGORY_APPLICATION,
						OrganRespCode.ISSUE_INSERT_UPDATE, "平台租赁发卡商必须设置有效期!");
			}
		}

		IssueCompany ic = issueCompanyDaoImpl
				.getIssueCompanyByIssueCompanyName(issueCompany
						.getIssueCompanyName().trim());
		if (ic != null) {
			throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL, "",
					"发卡商名称“" + ic.getIssueCompanyName() + "”已存在!");
		}
		// 发卡商ftp对账地址
		issueCompany.setChkAccFtpAddr(IssueCompany.ChkAccFtpAddr);
		// 默认赋值
		issueCompany = getInsertIssueCompany(issueCompany);
		// 插入平台机构主键表数据
		SysBranch sysBranch = new SysBranch(issueCompany.getIssueCompanyNo(),
				SysBranch.SYSBRANCH_ISSUECOMPANY);
		sysBranchDaoImpl.insertSysBranch(sysBranch);
		// 插入发卡商记录
		issueCompanyDaoImpl.insertIssueCompany(issueCompany);
		// 插入机构归属关系表
		SysBranchSubord sysBranchSubord = new SysBranchSubord();
		sysBranchSubord.setBranchNo(issueCompany.getIssueCompanyNo());
		sysBranchSubord.setSubBranchNo(issueCompany.getIssueCompanyNo());
		sysBranchSubord.setSubBranchType(SysBranch.SYSBRANCH_ISSUECOMPANY);
		sysBranchSubordDaoImpl.insertSysBranchSubord(sysBranchSubord);
		// 自动产生该发卡商下web日志记录员
		SysOpUser sop = new SysOpUser();
		BigInteger operId = pcpsCommonDaoImpl.getUniqueIntegerKey();
		sop.setOperId(operId);
		sop.setOperLogonName(issueCompany.getIssueCompanyNo() + "_web");
		String password = new SHA1()
				.getDigestOfString((sop.getOperLogonName() + sop
						.getOperLogonName()).getBytes());
		sop.setOperPasswd(password);
		sop.setOperBranchNo(issueCompany.getIssueCompanyNo());// 所属机构
		// sop.setRoleId(commonDaoImpl.getGlobalInfo().getIssueCompanyRoleId());//
		// 11
		sop.setName("发卡商网站日志用户");// 姓名
		sop.setSex("1");// 0 – 女 1 – 男
		sop.setStatus("1"); // 0 – 停用 1 – 启用
		sop.setIssueOper("1");// 发卡商管理员标识 0 – 否1 – 是
		sop.setInternetAgent("1");// 互联网代理操作员1 – 是
		sop.setPwdErrCnt(0);
		sop.setLastPwdChangeTime(commonDaoImpl.getDatabaseSysTime());
		sysOpUserDaoImpl.insertSysOpUserInfo(sop);

		// 插入数据库操作日志
		insertRecordingOperationLog(webInput, "创建发卡商", issueCompany,
				SysOperLog.operType_Add, "IssueCompanyName:"
						+ issueCompany.getIssueCompanyName());
		// 自动插入发卡商机构
		IssueBranch ib = new IssueBranch();
		ib.setIssueBranchNo(issueCompany.getIssueCompanyNo() + "99"); // 发卡商机构号
		ib.setIssueBranchName(issueCompany.getIssueCompanyName() + "虚拟总公司");// 发卡商机构名称
		ib.setIssueCompanyNo(issueCompany.getIssueCompanyNo());
		ib.setRegionNo(issueCompany.getRegionNo());
		ib.setStatus(IssueBranch.ISSUEBRANCH_STATUS_ACTIVATED);
		ib.setAllowActivate(IssueBranch.ISSUEBRANCH_ALLOWACTIVATE_NO);
		ib.setActivateBalance(new BigInteger("0"));
		ib.setCreditBalance(new BigInteger("0"));
		issueBranchBusinessImpl.insertIssueBranchInfo(webInput, ib);

		// 插入销售机构零散客户
		PersonalCustom personalCustom = new PersonalCustom();
		Global global = commonDaoImpl.getGlobalInfo();
		IdType idType = idTypeDaoImpl.getIdTypeByIdTypeName(global
				.getCommonIdTypeName());
		if (idType == null) {
			throw new SalesManageApplicationException(
					SalesManageApplicationException.ERRCODE_CATEGORY_APPLICATION,
					SalesManageRespCode.PERSONALCUSTOM_ARGS_NULL,
					"证件类型中无身份证类型!");
		}
		personalCustom.setIssueCompanyNo(issueCompany.getIssueCompanyNo());
		personalCustom.setIdTypeId(idType.getIdTypeId());
		personalCustom.setIdNo(IssueCompany.IDNO);
		personalCustom.setNationCodeId("CHN");
		personalCustom.setName("零散客户");
		// 新增操作员
		personalCustom.setOperId(webInput.getOperId());
		// 主键
		personalCustom.setPersonalId(commonDaoImpl.getUniqueIntegerKey());
		// 新增时间
		personalCustom.setCreateTime(commonDaoImpl.getDatabaseSysTime());
		personalCustom.setRemark("不提供购卡人时默认购卡人");
		personalCustom.setProfessionId(new BigInteger("20191"));
		personalCustom.setRiskLevel("1");
		// 插入个人客户信息
		personalCustomDaoImpl.insertPersonalCustom(personalCustom);
	}

	private IssueCompany getInsertIssueCompany(IssueCompany issueCompany) {
		Date tran = commonDaoImpl.getSysDateFormatYMD();
		// 发卡商交易日期，当前日期
		issueCompany.setTranDate(tran);
		// 默认值赋值
		issueCompany.setPwdErrLimit(24);// 密码错误时限： 初始为24hours
		issueCompany.setMaxPwdErrCnt(5);// 密码错误次数：
		issueCompany.setMaxCancelTimeLimit(1440);// 最大取消时限：
		issueCompany.setLastBalance(BigInteger.ZERO);// 帐户子系统上日余额：
		issueCompany.setBalance(BigInteger.ZERO);// 帐户子系统余额： >=0,初始为0,日终后更新
		issueCompany.setPersonalBuyerLimit(BigInteger.ZERO);// 个人购卡实名下限 默认0 不限制
		issueCompany.setOrganizeBuyerLimit(BigInteger.ZERO);// 单位购卡实名下限 默认0 不限制
		issueCompany.setEachCardOwnerLimit(new BigInteger("100000"));// 单卡实名下限
		// 默认1000
		// 不限制
		issueCompany.setEachCardBalanceLimit(new BigInteger("500000"));// 单卡余额上限
		// 为0
		issueCompany.setOrderAmountLimit(BigInteger.ZERO);// 销售/充值大于该限制时必须输入柜员授权密码
		issueCompany.setNonDirectSaleLimit(20000);// 非直营店单卡销售/充值上限Not Null
		// 默认20000分
		issueCompany.setContractAlertLimit(90);// 合同到期提醒时间 默认90，单位天
		issueCompany.setPersonTransferLimit(5000000);// 个人销售转账下限
		// 销售单总金额超过该限制时，所有付款信息里全为转账
		issueCompany.setOrganizeTransferLimit(500000);// 单位销售转账下限
		// 不限制，销售单总金额超过该限制时，所有付款信息里全为转账
		issueCompany.setDepositTransferLimit(new BigInteger("500000"));// 充值转账下限
		// 必须转账
		issueCompany.setCashUpperLimit(BigInteger.ZERO);// 现金库上限 Null
		// 默认为0，销售单收现金检查，
		issueCompany.setTempLossLimit(5);// 临时挂失时限： 单位天，默认5
		issueCompany.setLossLimit(7);// 挂失补发时限： 单位天，默认7
		issueCompany.setRedempLimit(90);// 赎回期限限制 90天
		issueCompany.setRedempEachCashLimit(10000);// 单笔赎回现金上限

		issueCompany
				.setAllowMrchDeposit(IssueCompany.ISSUECOMPANY_ALLOW_DEPOSIT);// 是否允许商户充值
		issueCompany.setMrchEachDepositLimit(20000);// 商户单笔充值上限 Decimal Not null
		// >=0
		issueCompany.setMrchDayDepositLimit(0);// 商户单卡单日累计充值上限 Decimal Not null

		issueCompany.setStatus(IssueCompany.ISSUECOMPANY_NORMAL_TRANSACTION);// 日终状态
		// 总公司抽成比率
		issueCompany.setCommissionRatio(0);
		// 跨地域商户开发单位抽成
		issueCompany.setMCommissionRatio(0);
		// 卡延期时间单位:月
		issueCompany.setDefaultExpired(12);
		// 0正常1日终处理
		return issueCompany;
	}

	@Override
	public void updateIssueCompanyInfo(PCPSWebInput webInput,
			IssueCompany issueCom) throws PCPSApplicationException {
		// 锁定查询出来的实体对象
		IssueCompany _issueCompany = issueCompanyDaoImpl
				.getIssueCompanyForUpdate(issueCom.getIssueCompanyNo());
		// 业务检查
		if (_issueCompany == null) {
			throw new OrganApplicationException(
					OrganApplicationException.ERRCODE_CATEGORY_APPLICATION,
					OrganRespCode.ISSUE_INSERT_UPDATE, "待修改发卡商数据库中不存在!");
		}

		// 平台机构管理员归属机构号为空
		if (!PCPSUtil.isEmpty(webInput.getOperBranchNo())) {
			// 超级管理员可以修改全部发卡商，发卡商自己才能改自己
			// 验证登录用户是否归属为当前发卡商
			if (!_issueCompany.getIssueCompanyNo().equals(
					webInput.getOperBranchNo())) {
				throw new OrganApplicationException(
						OrganApplicationException.ERRCODE_CATEGORY_APPLICATION,
						OrganRespCode.ISSUE_INSERT_UPDATE, "无权修改其他发卡商!");
			}
		}
		// 修改后的名字与当前名字不一致
		if (!issueCom.getIssueCompanyName().trim().equals(
				_issueCompany.getIssueCompanyName().trim())) {
			IssueCompany ic = issueCompanyDaoImpl
					.getIssueCompanyByIssueCompanyName(issueCom
							.getIssueCompanyName().trim());
			if (ic != null) {
				throw new OrganApplicationException(OrganRespCode.RC_ARGS_NULL,
						"", "发卡商名称“" + ic.getIssueCompanyName() + "”已存在!");
			}
		}
		// 对象转移
		_issueCompany.setIssueCompanyName(issueCom.getIssueCompanyName());
		_issueCompany.setShortlyName(issueCom.getShortlyName());
		_issueCompany.setMisTitle(issueCom.getMisTitle());
		_issueCompany.setEnglishTitle(issueCom.getEnglishTitle());
		_issueCompany.setAllowSelfService(issueCom.getAllowSelfService());
		_issueCompany.setCategory(issueCom.getCategory());
		_issueCompany.setActivate(issueCom.getActivate());
		_issueCompany.setLeaseExpired(issueCom.getLeaseExpired());
		_issueCompany.setAddress(issueCom.getAddress());
		_issueCompany.setTelephone(issueCom.getTelephone());
		_issueCompany.setRelation(issueCom.getRelation());
		_issueCompany.setRemark(issueCom.getRemark());
		// 修改发卡商
		issueCompanyDaoImpl.updateIssueCompany(_issueCompany);
		// 插入数据库操作日志
		insertRecordingOperationLog(webInput, "修改发卡商基本信息", issueCom,
				SysOperLog.operType_Edit, "IssueCompanyName:"
						+ issueCom.getIssueCompanyName());
	}

	/**
	 * 获取有效的发卡商参数
	 * 
	 * @param webInput
	 * @param issueCom
	 * @return
	 * @throws PCPSApplicationException
	 */
	private IssueCompany getValidateIssueCompany(PCPSWebInput webInput,
			IssueCompany issueCom) throws PCPSApplicationException {
		IssueCompany issueCompany = issueCompanyDaoImpl
				.getIssueCompanyByIssueCompanyNo(issueCom.getIssueCompanyNo());
		if (issueCompany == null) {
			throw new OrganApplicationException(
					OrganApplicationException.ERRCODE_CATEGORY_APPLICATION,
					OrganRespCode.ISSUE_INSERT_UPDATE, "待修改发卡商为空!");
		}

		if (webInput.getOperBranchNo() == null
				|| webInput.getOperBranchNo().length() != 6) {
			throw new OrganApplicationException(
					OrganApplicationException.ERRCODE_CATEGORY_APPLICATION,
					OrganRespCode.ISSUE_INSERT_UPDATE, "登录用户无权修改发卡商参数!");
		}
		if (!webInput.getOperBranchNo()
				.equals(issueCompany.getIssueCompanyNo())) {
			throw new OrganApplicationException(
					OrganApplicationException.ERRCODE_CATEGORY_APPLICATION,
					OrganRespCode.ISSUE_INSERT_UPDATE, "登录用户无权修改其他发卡商参数!");
		}
		return issueCompany;
	}

	@Override
	public void updateIssueCompanyBaseInfo(PCPSWebInput webInput,
			IssueCompany issueCom) throws PCPSApplicationException {
		// 取有效地发卡商参数
		IssueCompany issueCompany = getValidateIssueCompany(webInput, issueCom);

		// 简称
		issueCompany.setShortlyName(issueCom.getShortlyName());
		// 管理系统标题
		issueCompany.setMisTitle(issueCom.getMisTitle());
		// 管理系统英文标题
		issueCompany.setEnglishTitle(issueCom.getEnglishTitle());
		// 地址
		issueCompany.setAddress(issueCom.getAddress());
		// 电话
		issueCompany.setTelephone(issueCom.getTelephone());
		// 联系人
		issueCompany.setRelation(issueCom.getRelation());
		// 备注
		issueCompany.setRemark(issueCom.getRemark());

		issueCompany.setIssueCompanyName(issueCom.getIssueCompanyName());
		issueCompany.setChkAccFtpAddr(issueCom.getChkAccFtpAddr());
		issueCompany.setRINM(issueCom.getRINM());
		issueCompany.setFIRC(issueCom.getFIRC());
		issueCompany.setFICD(issueCom.getFICD());

		issueCompanyDaoImpl.updateIssueCompany(issueCompany);

		// 插入数据库操作日志
		insertRecordingOperationLog(webInput, "修改发卡商基本信息", issueCompany,
				SysOperLog.operType_Edit, "IssueCompanyName:"
						+ issueCompany.getIssueCompanyName());
	}

	@Override
	public void updateIssueCompanyBaseParameter(PCPSWebInput webInput,
			IssueCompany ic) throws PCPSApplicationException {
		// 取有效地发卡商参数
		IssueCompany company = getValidateIssueCompany(webInput, ic);

		if (!PCPSUtil.isEmpty(ic.getDepositSaleBranchNo())) {
			if (saleBranchDaoImpl.getSaleBranchBySaleBranchNo(ic
					.getDepositSaleBranchNo()) == null) {
				throw new OrganApplicationException(
						OrganApplicationException.ERRCODE_CATEGORY_APPLICATION,
						OrganRespCode.ISSUE_INSERT_UPDATE,
						"输入的默认充值归属销售机构编号系统不存在!");
			}
		}

		company.setPwdErrLimit(ic.getPwdErrLimit());
		company.setMaxPwdErrCnt(ic.getMaxPwdErrCnt());
		company.setMaxCancelTimeLimit(ic.getMaxCancelTimeLimit());
		company.setCashUpperLimit(ic.getCashUpperLimit());
		company.setMrchEachDepositLimit(ic.getMrchEachDepositLimit());
		company.setAllowMrchDeposit(ic.getAllowMrchDeposit());
		company.setDepositTransferLimit(ic.getDepositTransferLimit());
		company.setRedempLimit(ic.getRedempLimit());
		company.setContractAlertLimit(ic.getContractAlertLimit());
		company.setTempLossLimit(ic.getTempLossLimit());
		company.setLossLimit(ic.getLossLimit());
		company.setMrchDayDepositLimit(ic.getMrchDayDepositLimit());
		company.setOrderAmountLimit(ic.getOrderAmountLimit());
		company.setDefaultExpired(ic.getDefaultExpired());

		// 默认充值归属销售机构
		if (PCPSUtil.isEmpty(ic.getDepositSaleBranchNo()))
			company.setDepositSaleBranchNo(null);
		else
			company.setDepositSaleBranchNo(ic.getDepositSaleBranchNo());

		issueCompanyDaoImpl.updateIssueCompany(company);
		// 插入数据库操作日志
		insertRecordingOperationLog(webInput, "修改发卡商基本参数", company,
				SysOperLog.operType_Edit, "IssueCompanyName:"
						+ company.getIssueCompanyName());
	}

	@Override
	public void updateIssueCompanyCardParameter(PCPSWebInput webInput,
			IssueCompany issueCom) throws PCPSApplicationException {
		// 取有效地发卡商参数
		IssueCompany issueCompany = getValidateIssueCompany(webInput, issueCom);
		// 个人购卡实名下限
		issueCompany.setPersonalBuyerLimit(issueCom.getPersonalBuyerLimit());

		// 单位购卡实名下限
		issueCompany.setOrganizeBuyerLimit(issueCom.getOrganizeBuyerLimit());

		// 单卡实名下限
		issueCompany.setEachCardOwnerLimit(issueCom.getEachCardOwnerLimit());
		issueCompany
				.setEachCardBalanceLimit(issueCom.getEachCardBalanceLimit());

		issueCompany.setNonDirectSaleLimit(issueCom.getNonDirectSaleLimit());
		issueCompany.setRedempEachCashLimit(issueCom.getRedempEachCashLimit());
		issueCompany.setPersonTransferLimit(issueCom.getPersonTransferLimit());
		issueCompany.setOrganizeTransferLimit(issueCom
				.getOrganizeTransferLimit());

		issueCompanyDaoImpl.updateIssueCompany(issueCompany);

		// 插入数据库操作日志
		insertRecordingOperationLog(webInput, "修改发卡商卡交易参数", issueCompany,
				SysOperLog.operType_Edit, "IssueCompanyName:"
						+ issueCompany.getIssueCompanyName());
	}

	private void insertRecordingOperationLog(PCPSWebInput webInput,
			String logName, IssueCompany obj, String operType,
			String lastFieldName) throws PCPSApplicationException {
		String logRemark = PCPSUtil.RecordingOperationLog(obj, lastFieldName);
		if (!PCPSUtil.isEmpty(logRemark)) {
			// 插入数据库日志
			SysOperLog sysOperLog = new SysOperLog();
			if (webInput != null && webInput.getOperId() != null) {
				sysOperLog.setOperId(webInput.getOperId());
				sysOperLog.setOperType(operType);
				sysOperLog.setLogName(logName);
				if (webInput != null) {
					sysOperLog.setIpAddress(webInput.getIpAddress());
				}
				if (!PCPSUtil.isEmpty(webInput.getOperBranchNo())) {
					sysOperLog.setIssueCompanyNo(webInput.getOperBranchNo()
							.substring(0, 6));
					sysOperLog.setBranchNo(webInput.getOperBranchNo());
				}
				sysOperLog.setRemark(logRemark);
				sysOperLogDaoImpl.insertSysOperLog(sysOperLog);
			}
		}
	}

	@Override
	public void updateIssueCompanyCommissionRatio(PCPSWebInput webInput,
			IssueCompany ic) throws PCPSApplicationException {
		if (webInput == null && PCPSUtil.isEmpty(webInput.getOperBranchNo())
				|| webInput.getOperId() == null) {
			throw new OrganApplicationException(
					OrganApplicationException.ERRCODE_CATEGORY_APPLICATION,
					OrganRespCode.ISSUE_INSERT_UPDATE, "登录用户参数为空!");
		}
		if (PCPSUtil.isEmpty(ic.getIssueCompanyNo())
				|| ic.getCommissionRatio() == null
				|| ic.getMCommissionRatio() == null) {
			throw new OrganApplicationException(
					OrganApplicationException.ERRCODE_CATEGORY_APPLICATION,
					OrganRespCode.ISSUE_INSERT_UPDATE, "发卡商参数传入为空!");
		}
		// 锁定查询出来的实体对象
		IssueCompany _issueCompany = issueCompanyDaoImpl
				.getIssueCompanyForUpdate(ic.getIssueCompanyNo());
		// 业务检查
		if (_issueCompany == null) {
			throw new OrganApplicationException(
					OrganApplicationException.ERRCODE_CATEGORY_APPLICATION,
					OrganRespCode.ISSUE_INSERT_UPDATE, "待修改发卡商数据库中不存在!");
		}
		if (!webInput.getOperBranchNo().substring(0, 6).equals(
				ic.getIssueCompanyNo())) {
			throw new OrganApplicationException(
					OrganApplicationException.ERRCODE_CATEGORY_APPLICATION,
					OrganRespCode.ISSUE_INSERT_UPDATE, "不可设置其他发卡商收益分配比率!");
		}

		// 对象转移
		_issueCompany.setCommissionRatio(ic.getCommissionRatio());
		_issueCompany.setMCommissionRatio(ic.getMCommissionRatio());
		// 修改发卡商
		issueCompanyDaoImpl.updateIssueCompany(_issueCompany);
		// 插入数据库操作日志
		sysOperLogDaoImpl.insertSysOperLogInfo(webInput,
				SysOperLog.operType_Edit, "修改发卡商收益分配比率", "总公司抽成比率"
						+ ic.getCommissionRatio() + "商户开发单位收益分配比率"
						+ ic.getMCommissionRatio());
	}
}
